package my.eureka.provider.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 哲 on 2016/11/29.
 */
@RestController
public class ComputeController {

    private static final Logger logger = Logger.getLogger(ComputeController.class);

    @Autowired
    private DiscoveryClient client;

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public Integer add(@RequestParam int a, @RequestParam int b){

        ServiceInstance instance = client.getLocalServiceInstance();
        int ret = a + b;
        logger.info("controller /add, Host:"+instance.getHost()+", Port:"+instance.getPort()+", Service_id:"+instance.getServiceId());

        return ret;
    }

}
